﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Platform.Storage.Redis
{
	public class RedisIndexCommands : RedisCommandsBase
	{

		public RedisIndexCommands( string indexName, RedisMessageChannel channel )
			: base( channel )
		{
			this.IndexName = indexName;
		}

		public string IndexName
		{ get; private set; }


		public int Add( IndexItem item, params IndexItem[] moreItems )
		{
			return this.Channel.ExecuteInt32( "ZADD", moreItems.AsString().InsertFirst( item.AsString() ).InsertFirst( this.IndexName ) );
		}

		public int Update( IndexItem item, params IndexItem[] moreItems )
		{
			int added = this.Add( item, moreItems );
			int total = 1;

			if ( moreItems != null )
				total += moreItems.Length;

			return total - added;
		}
	}

}
